package it.appcatalogobase;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Properties;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.util.Log;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings.TextSize;
import android.widget.ImageView;
import android.widget.TextView;
import android.os.Build;

public class ProductDettaglioActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_product_dettaglio);

//		if (savedInstanceState == null) {
//			getSupportFragmentManager().beginTransaction()
//					.add(R.id.container, new PlaceholderFragment()).commit();
//		}
		
		Intent i = getIntent();
		String name = i.getStringExtra("name");
		String des = i.getStringExtra("des");
		String imm = i.getStringExtra("imm");
		TextView tNome = (TextView) findViewById(R.id.nome);
		tNome.setText(name);
		TextView tDes = (TextView) findViewById(R.id.descrizione);
		String des1 = "'<p style='text-align: center;'><span style='font-size: 12pt; color: #ff0000;'><strong>Frog Revolution </strong></span></p>\r\n<p><span style='font-size: 10pt;'>Un mix perfetto di design e praticit&agrave;, che stimola il piacere dello sguardo.</span></p>\r\n<p><span style='font-size: 10pt;'>La Frog &egrave; una macchina da caff&egrave; espresso a cialde destinata sia al mercato domestico che quello aziendale. </span></p>\r\n<p><span style='font-size: 10pt;'>Il suo design innovativo, la sua semplicit&agrave; e la qualit&agrave; delle sue componenti, la rendono un bene strumentale affidabile a cui puntare in tutta tranquillit&agrave;. </span></p>\r\n<p><span style='font-size: 10pt;'><strong>DIMENSIONI:</strong></span></p>\r\n<ul>\r\n<li><span style='font-size: 10pt;'>Larghezza: 22 cm </span></li>\r\n<li><span style='font-size: 10pt;'>Altezza: 40 cm</span></li>\r\n<li><span style='font-size: 10pt;'>Profondit&agrave;: 32 cm</span></li>\r\n<li><span style='font-size: 10pt;'>Peso: 6.5 Kg</span></li>\r\n</ul>\r\n<p><span style='font-size: 10pt;'><strong>CARATTERISTICHE TECNICHE</strong></span></p>\r\n<ul>\r\n<li><span style='font-size: 10pt;'>Potenza normale 650 W </span></li>\r\n<li><span style='font-size: 10pt;'>Voltaggio 230 V</span></li>\r\n<li><span style='font-size: 10pt;'>Sistema di decalcificazione rapido </span></li>\r\n<li><span style='font-size: 10pt;'>Alloggio bottiglia d'acqua </span></li>\r\n</ul>\r\n<p><span style='font-size: 10pt;'><strong>ACCESSORI</strong></span></p>\r\n<ul>\r\n<li><span style='font-size: 10pt;'>Vano porta cialde e bicchieri</span></li>\r\n</ul>";
		des=des.replace("\\/", "/");
		des=des.replace("\\", "/");
		des.replace("/r","<br/>");
		des.replace("/n","<br/>");
		des=des.replace("\"", "'");
		des=des.replace("&lt;", "<");
		des=des.replace("&gt;", ">");
		Log.v("prova", des);
		
//		des="<![CDATA["+des+"]]>";
//		Properties p = new Properties();
//		try {
//			p.load(getAssets().open("config.properties"));
//		} catch (IOException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		p.setProperty("value2", "<![CDATA["+des+"]]>");
		System.out.println(des);
		try {
			tDes.setText(URLDecoder.decode(Html.fromHtml(des).toString(), "ISO-8859-1"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		ImageView immV = (ImageView) findViewById(R.id.immagine);
		Bitmap bm = null;
		try {
			bm = BitmapFactory.decodeStream(openFileInput(imm));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		immV.setImageBitmap(bm);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.product_dettaglio, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
//		if (id == R.id.action_settings) {
//			return true;
//		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
//	public static class PlaceholderFragment extends Fragment {
//
//		public PlaceholderFragment() {
//		}
//
//		@Override
//		public View onCreateView(LayoutInflater inflater, ViewGroup container,
//				Bundle savedInstanceState) {
//			View rootView = inflater.inflate(
//					R.layout.fragment_product_dettaglio, container, false);
//			return rootView;
//		}
//	}

}
